package athlete;

import java.util.Random;

public class Athlete extends Person implements Cyclist, Runner, Swimmer{
	private int runFrequency;
	private int runCoverage;
	private int cycleFrequency;
	private int cycleCoverage;
	private int swimFrequency;
	private int swimCoverage;
	
	public Athlete(String name){
		super(name);
		Random r = new Random();
		this.runFrequency = r.nextInt(10) + 5;
		this.runCoverage = r.nextInt(20) + 10;
		this.cycleFrequency = r.nextInt(10) + 5;
		this.cycleCoverage = r.nextInt(20) + 5;
		this.swimFrequency = r.nextInt(10) + 5;
		this.swimCoverage = r.nextInt(20) + 5;
	}
	
	public Athlete(String name, int runFrequency, int runCoverage, int cycleFrequency, int cycleCoverage, int swimFrequency, int swimCoverage){
		super(name);
		this.runFrequency = runFrequency;
		this.runCoverage = runCoverage;
		this.cycleFrequency = cycleFrequency;
		this.cycleCoverage = cycleCoverage;
		this.swimFrequency = swimFrequency;
		this.swimCoverage = swimCoverage;
	}

	@Override
	public int cycle(int totalDistance) {
		int totalCycleTime = 0;
		int distCycled = 0;
		while(totalDistance>0){
			distCycled = distCycled + cycleCoverage*cycleFrequency;
			totalCycleTime++;
			totalDistance -= distCycled;
		}
		return totalCycleTime;
	}

	@Override
	public int run(int totalDistance) {
		int totalRunTime = 0;
		int distRan = 0;
		while(totalDistance>0){
			distRan = distRan + runCoverage*runFrequency;
			totalRunTime++;
			totalDistance -= distRan;
		}
		return totalRunTime;
	}

	@Override
	public int swim(int totalDistance) {
		int totalSwimTime = 0;
		int distSwam = 0;
		while(totalDistance>0){
			distSwam = distSwam + swimCoverage*swimFrequency;
			totalSwimTime++;
			totalDistance -= distSwam;
		}
		return totalSwimTime;
	}
}
